<?php
include_once('../model/SendMail.php');
include_once('../model/ApplyRegistryFromWeb.php');

$result = false;

if(isset($_POST['Type_Loan'])) {
	if(isset($_POST['Name']) && isset($_POST['Phone']) && isset($_POST['Email']) && isset($_POST['City']) && isset($_POST['Net_Salary'])) {
		$nameloan = $_POST['Type_Loan'];
		
		$fullname = $_POST['Name'];
		$phonenumber = $_POST['Phone'];
		$email = $_POST['Email'];
		$contry = $_POST['City'];
		$sumsalary = $_POST['Net_Salary'];// tong luong
		$dayofbirth = "";
		$profession = "";// nghe nghiep
		$amountloan = "";// so tien muon vay
		$giatritaisan = "";// gia tri tai san
		$monthloan = "";// so thang muon vay
		
		if(isset($_POST['birthday'])) {
			$dayofbirth = $_POST['birthday'];
		}
		if(isset($_POST['Employment_Status'])) {
			$profession = $_POST['Employment_Status'];
		}
		if(isset($_POST['Loan_Amount'])) {
			$amountloan = $_POST['Loan_Amount'];
		}
		if(isset($_POST['property_value'])) {
			$giatritaisan = $_POST['property_value'];
		}
		if(isset($_POST['obligations'])) {
			$monthloan = $_POST['obligations'];
		}
		
		
		$nameloan = strtoupper($nameloan);
		$body = '<style>table tr {height: 30px;min-height: 30px;}</style><div style="border: 1px solid; width: 600px; min-height: 300px;"><div style="width: 100%; min-height: 50px; background: #8DAE48; text-align: center; margin-top: -20px;"><h2 style="color: #FFF; padding-top: 10px;">ĐĂNG KÝ THÔNG TIN CHO VAY '.$nameloan.'</h2></div><div style="min-height: 250px; padding: 5px;"><table><tr><th align="left" valign="top">Tên Khách Hàng:</th><td align="left" valign="top">'.$fullname.'</td></tr><tr><th align="left" valign="top">Ngày Sinh:</th><td align="left" valign="top">'.$dayofbirth.'</td></tr><tr><th align="left" valign="top">Hình Thức Vay:</th><td align="left" valign="top">'.$nameloan.'</td></tr><tr><th align="left" valign="top">Số Điện Thoại:</th><td align="left" valign="top">'.$phonenumber.'</td></tr><tr><th align="left" valign="top">Email:</th><td align="left" valign="top">'.$email.'</td></tr><tr><th align="left" valign="top">Tỉnh Thành:</th><td align="left" valign="top">'.$contry.'</td></tr><tr><th align="left" valign="top">Nghề Nghiệp:</th><td align="left" valign="top">'.$profession.'</td></tr><tr><th align="left" valign="top">Số Tiền Muốn Vay:</th><td align="left" valign="top">'.$amountloan.'</td></tr><tr><th align="left" valign="top">Số Tháng Muốn Vay:</th><td align="left" valign="top">'.$monthloan.'</td></tr><tr><th align="left" valign="top">Tổng Lương Tháng:</th><td align="left" valign="top">'.$sumsalary.'</td></tr><tr><th align="left" valign="top">Giá Trị Tài Sản:</th><td align="left" valign="top">'.$giatritaisan.'</td></tr></table></div></div>';
		$result = false;
		//smtpmailer($fullname."_".$nameloan, $body);
		if (insertApplyWeb(time(), $fullname."_".$nameloan, $body)) {
			$result = true;
		}
		echo json_encode($result);
		return;
	}
}

echo json_encode($result);
?>